//
//  XZMachineModeMyselfVC.m
//  Teecloud
//
//  Created by PC on 2018/11/20.
//  Copyright © 2018年 小志. All rights reserved.
//
#import "XZTimeInfo.h"
#import "XZLeaveApplyDetailVC.h"
#import "XZMachineModeMyselfVC.h"
#import "XZMachineModeMyselfCell.h"
@interface XZMachineModeMyselfVC ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@end
#define Identifier @"MachineModeMyselfV"
@implementation XZMachineModeMyselfVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"考勤查询";
    self.view.backgroundColor = kWhiteColor;
    [self QueryRandTimeInfo2];
}
#pragma mark - QueryRandTimeInfo2
- (void)QueryRandTimeInfo2{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:FROM_IOS forKey:@"from"];
    [dict setValue:[XGMArchiverTools cacheForKey:BUSIORGID] forKey:@"busiOrgId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_UserId] forKey:@"userId"];
    [dict setValue:[XGMArchiverTools cacheForKey:USER_identifierNumber] forKey:@"loginFinger"];
    [dict setValue:self.groupId forKey:@"groupId"];
    kWeakObject(self)
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HJNetwork POSTWithURL:[NSString stringWithFormat:@"ajax-api.ashx?$c=TeeyunApp&$m=QueryRandTimeInfo2&$v=%@",VERSION] parameters:dict cachePolicy:HJCachePolicyIgnoreCache callback:^(id responseObject, NSError *error) {
        [weakself.tableView.mj_header endRefreshing];
        [MBProgressHUD hideHUDForView:weakself.view animated:YES];
        if (!error) {
            if ([[responseObject objectForKey:RESULT_NAME_Success] boolValue]) {
                [weakself.dataSource removeAllObjects];
                NSArray *array = [XZTimeInfo mj_objectArrayWithKeyValuesArray:[responseObject objectForKey:RESULT_NAME_Data]];
                [weakself.dataSource addObjectsFromArray:array];
                if (self.dataSource.count == 0) {
                    [self.tableView setupEmptyDataText:@"暂无数据" secoundText:@"" buttonTit:@"" verticalOffset:0 emptyImage:NODATAIMG tapBlock:^{
                        
                    } butClick:^{
                        
                    }];
                }
                [weakself.tableView reloadData];
            }else{
                [MBProgressHUD showErrorOrSuc:[responseObject objectForKey:RESULT_NAME_Message] toView:weakself.view];
            }
        }else{
            [MBProgressHUD showErrorOrSuc:@"网络异常" toView:weakself.view];
        }
    }];
}
#pragma mark - TableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    kWeakObject(self)
    XZMachineModeMyselfCell *machineModeMyselfCell = [tableView dequeueReusableCellWithIdentifier:Identifier];
    XZTimeInfo *model = self.dataSource[indexPath.row];
    machineModeMyselfCell.model = model;
    //点击请假
    machineModeMyselfCell.leaveBlock = ^(NSString * _Nonnull leaveApplyId) {
        XZLeaveApplyDetailVC *leaveApplyDetailVC = [[XZLeaveApplyDetailVC alloc]init];
        leaveApplyDetailVC.id = leaveApplyId;
        [weakself.navigationController pushViewController:leaveApplyDetailVC animated:true];
    };
    return machineModeMyselfCell;
}
#pragma mark - TableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    XZTimeInfo *model = self.dataSource[indexPath.row];
    return model.cellHeight;
}

#pragma mark - Setter
- (NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = [[NSMutableArray alloc]init];
    }
    return _dataSource;
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, DEVICE_HEIGHT-kBottomSafeHeight-kNavBarAndStatusBarHeight) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator =false;
        _tableView.separatorStyle =UITableViewCellSeparatorStyleNone;
        //注册
        [_tableView registerNib:[UINib nibWithNibName:@"XZMachineModeMyselfCell" bundle:nil] forCellReuseIdentifier:Identifier];
        //上下拉刷新
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(QueryRandTimeInfo2)];
        [self.view addSubview:_tableView];
    }
    return _tableView;
}
@end
